﻿#Requires AutoHotkey v2.0
#SingleInstance Force

#Include _lib\Extend.ahk
#Include _lib\Tip.ahk
#Include _lib\HotStringEx.ahk
#Include _lib\log.ahk
#Include _lib\AhkCmdLine.ahk
#Include _lib\Fs.ahk
#Include _lib\Path.ahk

#Hotstring EndChars `t `n.';/
TraySetIcon "./Meow.ico"

#Include lightCtrl.ahk
#Include mediaCtrl.ahk
#Include quickLook.ahk
#Include simpleMove.ahk
#Include volumeCtrl.ahk
#Include blockMouse.ahk
#Include windowTopCtrl.ahk
#Include setDesktopIconState.ahk
#Include schedule\index.ahk

CoordMode "ToolTip", "Screen"
CoordMode "Pixel", "Screen"
CoordMode "Mouse", "Screen"

tray := A_TrayMenu
tray.delete()
  , tray.add('Folder', (*) => Run(A_ScriptDir))

sm := Menu()
tray.add('use', sm)
  , tray.add()
  , tray.Add('Pause', (*) => Suspend())
  , tray.add('Reload', (*) => Reload())
  , tray.add('Exit', (*) => ExitApp())
  , tray.Default := 'Pause'

fList := []

GetList(dir) {
  loop files dir '/*.*', 'FD' {
    if fs.IsDir(A_LoopFilePath) {
      if fs.IsHidden(A_LoopFilePath) or A_LoopFileName[1] = '_'
        continue
      else GetList(A_LoopFilePath)
    } else {
      p := Path.Parse(A_LoopFileFullPath)
      if p.ext != 'ahk' or p.name[1] = '_' or p.name[1] = '.'
        continue
      fList.Push([p.nameNoExt, A_LoopFileFullPath])
    }
  }
}
GetList('./scripts')
fList.foreach(v => sm.Add(v[1], (*) => Run(v[2])))

$LAlt:: {
  if A_PriorHotkey = A_ThisHotkey && A_TimeSincePriorHotkey < 5
    return
  Send('{LAlt Down}'), KeyWait('LAlt'), Send('{LAlt Up}')
}

main_actions := [
  ['Date', (*) => SendInput(FormatTime(, "yyyy/MM/dd"))],
  ['Time', (*) => SendInput(FormatTime(, "HH:mm:ss"))]
]
hse := HotStringEx('~;', 1)
hse.Register(main_actions*)
::;datetime:: {
  SendInput(FormatTime(, "yyyy/MM/dd_HH:mm:ss/tt"))
}


>!LButton:: {
  CoordMode "Mouse", "Screen"
  MouseGetPos(&px, &py), WinGetPos(&wx, &wy, , , 'A')
  dx := wx - px, dy := wy - py
  SetWinDelay -1
  While GetKeyState("LButton", "P")
    MouseGetPos(&nx, &ny), WinMove(nx + dx, ny + dy, , , "A")
  if (A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 300)
    try WinMaximize('A')
}

logger := Log('.\_log.txt')
; logger.silent := true
if InStr(ParseCmdLine(GetCommandLine()).switches.Join(), '/restart')
  logger.Info('RESTART')
else {
  logger.Info('Script Start')
  OnExit((*) => logger.Info('Script Exit'))
}

<+<!q:: Run('.\scripts\_windowTransparentCtrl.ahk')

#Include G:\AHK\_SELF\meow.ahk
